require(["common", "eventManager", "coAjax", "queryString", "href", "hash_routie", "WX", "jQuery.qrcode"], function(jSouper, eventManager, coAjax, QueryString, href, hash_routie, WX) {
	hash_routie.on("draw-item", function() {
		var qs = new QueryString(location.hash);
		var draw_id = qs.get("id");
		if (!draw_id) {
			myConfirm("抽奖信息有误！");
			href.jump("/mobile.main.html");
			return;
		};
		coAjax.get(appConfig.bus_lottery_by_id + draw_id, {
			bus_id: appConfig.bus_id
		}, function(draw_result) {
			if (!draw_result.result) {
				myConfirm("查询不到抽奖信息或已过期！");
				href.jump("/mobile.main.html");
				return;
			};
			App.set("$Cache.drawitem.detail", draw_result.result);
			console.log(draw_result)
		});

		App.set("$Event.drawitem.draw", function() {
			if (!App.get("loginer")) {
				myConfirm("请先登陆后再进行抽奖！", function() {
					href.jump("mobile.main.html#default/sign_in");
				});
				return;
			};
			coAjax.post(appConfig.user.lottery_draw + draw_id, {
				bus_id: appConfig.bus_id
			}, function(result) {
				console.log(result);
				if (!result.result) {
					myConfirm("很遗憾，您没有抽中奖品T_T");
					return;
				};
				var str = "恭喜您中了" + result.result.title + "，奖品为：" + result.result.content.info.intro;
				myConfirm(str);
				console.log("中奖信息：", result.result);
			}, function(error, response, body) {
				if (body) {
					myConfirm(body);
				} else {
					myConfirm("网络错误，请联系网站人员或稍后重试！");
				};
			});
		});
	});

	App.set("$Event.drawitem.show_roles", function() {
		App.model.toggle("$Cache.drawitem.show_roles");
	});
});